﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HA.ModFlow.Domain.DomainLayer;

using System.Collections.ObjectModel;
namespace HA.ModFlow.Controls
{
    class PCWellCollections : PCBase
    {
        public PCWellCollections(WellCollection wel)
        {
            this.Wells = wel;
            this._periodStep = new List<int>();

            for (int i = 0; i < wel.NPeriods; i++)
            {

                this._periodStep.Add(i + 1);

            }

            this._lstUsePrecious = new List<bool>();

            this._lstUsePrecious.AddRange(wel.IsUsePrecious);




            this.Wellcs = new ObservableCollection<PCWell>();

            foreach (Well item in wel.InnerList)
            {
                PCWell pc = new PCWell((Well)item.Clone());

                this.Wellcs.Add(pc);

            }

        }

        WellCollection Wells;

        bool _isShowId = true;

        public bool IsShowId
        {
            get { return _isShowId; }
            set { _isShowId = value; }
        }




        List<bool> _lstUsePrecious;

        public bool UsePreciousEnabled
        {
            get
            {
                if (this._currentPeriod == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

        }

        public bool UsePrecious
        {
            get
            {
                if (_lstUsePrecious.Count == 0)
                    return false;
                return this._lstUsePrecious[this._currentPeriod];


            }
            set
            {



                this._lstUsePrecious[this._currentPeriod] = value;
                this.Wells.IsUsePrecious[this._currentPeriod] = value;

                this.OnPropertyChanged("UsePrecious");

            }
        }


        //具体的index值

        int _currentPeriod = 0;

        public int CurrentPeriod
        {
            get { return _currentPeriod; }
            set
            {


                _currentPeriod = value;

                this.UsePrecious = this.Wells.IsUsePrecious[_currentPeriod];

                foreach (PCWell item in this.Wellcs)
                {
                    item.CurrentIndex = this._currentPeriod;

                }

                this.OnPropertyChanged("UsePreciousEnabled");

                this.OnPropertyChanged("UsePrecious");


            }
        }





        List<int> _periodStep;

        public List<int> PeriodStep
        {
            get { return _periodStep; }

        }



        ObservableCollection<PCWell> _Wellcs;

        public ObservableCollection<PCWell> Wellcs
        {
            get { return _Wellcs; }
            set { _Wellcs = value; }
        }
        public void CreateNew()
        {
            Well well = new Well(1, 1, 1, this.Wells.Nrows, this.Wells.Ncols, this.Wells.Nlayers, this._periodStep.Count);

            PCWell pcNew = new PCWell(well);

            this.Wellcs.Add(pcNew);
        }
       

        public void ConfirmData()
        {

            List<Well> wells = new List<Well>();

            foreach (PCWell item in this.Wellcs)
            {
                wells.Add(item.Well);

            }

            this.Wells.ResetWells(wells);

            this.Wells.ResetIsUsePrecious(this._lstUsePrecious);





        }
        /// <summary>
        /// 检查层行列的正确定性
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <param name="layer"></param>
        /// <param name="index"></param>
        /// <param name="isIndexId"></param>
        /// <returns></returns>
        public bool CheckInputIJKorIndex(int row, int col, int layer, int index, bool isIndexId)
        {
            foreach (PCWell item in this.Wellcs)
            {
                if (!isIndexId)
                {
                    if (item.I <= 0 || item.I > row)//行
                    {
                        System.Windows.MessageBox.Show("不存在第 " + item.I + " 行，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                        return false;
                    }
                    if (item.J <= 0 || item.J > col)
                    {
                        System.Windows.MessageBox.Show("不存在第 " + item.J + " 列，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                        return false;
                    }
                    if (item.K <= 0 || item.K > layer)
                    {
                        System.Windows.MessageBox.Show("不存在第 " + item.K + " 层，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                        return false;
                    }
                }
                else
                {
                    if (item.Index <= 0 || item.Index > index)
                    {
                        System.Windows.MessageBox.Show("不存在 " + item.Index + " 单元格ID，请核查！", "提示", System.Windows.MessageBoxButton.OK);
                        return false;
                    }

                }
            }

            return true;
        }

    }

    public class PCWell : PCBase
    {


        public PCWell(Well well)
        {
            this._well = well;

        }

        Well _well;

        public Well Well
        {
            get { return _well; }
        }





        int _currentIndex = 0;

        public int CurrentIndex
        {
            get { return _currentIndex; }
            set
            {


                _currentIndex = value;


                this.OnPropertyChanged("RechargeRates");
                this.OnPropertyChanged("Name");
                //this.OnPropertyChanged("Elevation");



            }
        }




        public int Index
        {
            get
            {
                return this._well.Index;


            }
            set
            {


                this._well.Index = value;

                this.OnPropertyChanged("I");
                this.OnPropertyChanged("J");
                this.OnPropertyChanged("K");

            }
        }



        public int I
        {
            get { return this._well.I; }
            set
            {
                this._well.I = value;

                this.OnPropertyChanged("Index");


            }

        }


        public int J
        {
            get { return this._well.J; }
            set
            {
                this._well.J = value;

                this.OnPropertyChanged("Index");
            }
        }


        public int K
        {
            get { return this._well.K; }
            set
            {
                this._well.K = value;


                this.OnPropertyChanged("Index");

            }
        }


        public double RechargeRates
        {
            get { return this._well.RechargeRates [this._currentIndex]; }

            set { this._well.RechargeRates[this._currentIndex] = value; }
        }


        public string Name
        {
            get { return this._well.Name ; }

            set { this._well.Name = value; }

        }

        //public double Elevation
        //{

        //    get { return this._well.Elevation[this._currentIndex]; }

        //    set { this._well.Elevation[this._currentIndex] = value; }


        //}

    }
}

